Skip to content

fix: crash on startup when MERGE_HEAD points to an annotated tag - #2904

Merged
JC-Chung merged 1 commit into
sourcegit-org:developfrom
bertyhell:fix/merge-head-annotated-tag-crash
Nov 27, 2026
Merged

JC-Chung merged 1 commit into
sourcegit-org:developfrom
bertyhell:fix/merge-head-annotated-tag-crash

Conversation

@bertyhell

@bertyhell bertyhell commented Nov 26, 2026 •

Copy link
Copy Markdown

Problem

When a repository has an in-progress merge of an annotated tag (e.g. git merge v1.2.3), MERGE_HEAD contains the tag object's SHA rather than a commit SHA. Opening that repository crashes SourceGit, and because the repository is reopened on launch, the app crashes again immediately on every restart.

System.FormatException: The input string '5dcf7867600551f75f01629606c135e627077a56' was not in a correct format.
   at SourceGit.Commands.QuerySingleCommit.Parse(Command.Result rs)
   at SourceGit.ViewModels.MergeInProgress..ctor(Repository repo)
   at SourceGit.ViewModels.WorkingCopy.UpdateInProgressState()
   ...

git show <tag-sha> prints the tag header (tag ..., Tagger: ..., message) before the commit. That shifts the formatted lines, so ulong.Parse(lines[4]) gets the commit SHA instead of the author timestamp.

Steps to reproduce

  1. Create a repo where merging an annotated tag causes a conflict:
    git init -b main repro && cd repro
    echo a > f && git add f && git commit -m init
    git switch -c other && echo b > f && git commit -am other
    git tag -a v1.0.0 -m v1.0.0
    git switch main && echo c > f && git commit -am main
    git merge v1.0.0   # conflicts, leaving the merge in progress
  2. Check that MERGE_HEAD holds the tag object, not a commit: git cat-file -t $(cat .git/MERGE_HEAD) prints tag.
  3. Open the repo in SourceGit. It crashes with the FormatException below, and crashes again on every restart while the repo stays open.

Fix

  • QuerySingleCommit now asks for <sha>^{commit}, so tags are peeled to their commit. This also covers the other callers that can pass a tag SHA.
  • Author and committer timestamps are parsed with TryParse. Unexpected output now returns null, which all callers already handle, instead of throwing on the UI thread.

Testing

  • Reproduced on a real repo with MERGE_HEAD pointing at an annotated tag: before the fix the app crashed on launch, after the fix it opens normally.
  • Checked that git show ... <tag-sha>^{commit} returns the commit fields in the expected order.

🤖 Generated with Claude Code

Merging an annotated tag (e.g. `git merge v1.2.3`) writes the tag object's
SHA to MERGE_HEAD. `git show <tag-sha>` then prints the tag header before
the commit, shifting every line, and `QuerySingleCommit.Parse` threw a
FormatException trying to parse a SHA as the author timestamp. Because the
in-progress state is read on repository load, the app crashed every time it
was reopened.

Peel the revision to its commit with `^{commit}`, and parse the timestamps
with TryParse so unexpected output returns null instead of crashing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JC-Chung JC-Chung self-assigned this Nov 27, 2026
@JC-Chung JC-Chung added the bug Something isn't working label Nov 27, 2026
@JC-Chung
JC-Chung merged commit b3d10a3 into sourcegit-org:develop Nov 27, 2026
14 checks passed
@bertyhell
bertyhell deleted the fix/merge-head-annotated-tag-crash branch November 27, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants